import { createApp } from 'vue'
import NotificationComponent from '../newtab/components/NotificationComponent.vue'

class NotificationService {
  constructor() {
    this.instance = null
    this.init()
  }

  init() {
    // 创建挂载点
    const container = document.createElement('div')
    document.body.appendChild(container)
    
    // 创建组件实例
    const app = createApp(NotificationComponent)
    this.instance = app.mount(container)
  }

  show(message, type = 'info', duration = 3000) {
    if (this.instance) {
      this.instance.show(message, type, duration)
    }
  }

  success(message, duration) {
    this.show(message, 'success', duration)
  }

  error(message, duration) {
    this.show(message, 'error', duration)
  }

  warning(message, duration) {
    this.show(message, 'warning', duration)
  }

  info(message, duration) {
    this.show(message, 'info', duration)
  }
}

export default new NotificationService()